package com.example.ll_video.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatToggleButton;

import com.example.ll_video.utils.CommonDialog;
import com.example.ll_video.utils.SPUtils;
import com.example.ll_video.utils.ToastUtils;
import com.example.ll_video.R;
import com.qmuiteam.qmui.widget.QMUILoadingView;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;


import java.util.Objects;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {
    @BindView(R.id.toggle_btn)
    AppCompatToggleButton toggleBtn;
    @BindView(R.id.clean_cache)
    TextView cleanCache;
    @BindView(R.id.tv_share_app)
    TextView tvShareApp;
    @BindView(R.id.tv_about_app)
    TextView tvAboutApp;
    @BindView(R.id.btn_exit)
    QMUIRoundButton btnExit;

    QMUITipDialog qmuiTipDialog;

    private Handler handler = new Handler(Objects.requireNonNull(Looper.myLooper())) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            ToastUtils.showTextToast(context, "缓存已清除");
        }
    };

    @Override
    public void onCreate() {
        contentView(R.layout.activity_setting_ll);
        ButterKnife.bind(this);
        qmuiTipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .create(false);

    }

    CommonDialog commonDialog;

    @OnClick({R.id.clean_cache, R.id.tv_share_app, R.id.tv_about_app, R.id.btn_exit})
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.clean_cache:
                commonDialog = new CommonDialog(context, "确认是否清除缓存", "取消", "确认", new CommonDialog.DialogClick() {
                    @Override
                    public void selectBtn(String str, int i) {
                        commonDialog.closeDialog();
                        if (i == 1) {
                            handler.sendEmptyMessageDelayed(1,200);
                        }
                    }
                });
                commonDialog.setTitle("清除缓存");
                commonDialog.showDialog();
                break;
            case R.id.tv_share_app:

                break;
            case R.id.tv_about_app:
                intent = new Intent(context, AboutActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_exit:
                SPUtils.clear(context);
                intent = new Intent(context, LoginActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }

}
